package com.lz.ad.canal.config.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * Created by Li Tiefei on 2019/3/9.
 */
@Component
@Slf4j
public class KafkaProducer {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    public void sendMsgToTopic(String topic,String msg){
        kafkaTemplate.send(topic,msg);
        log.debug("send over, topic:{}, msg {}.",topic,msg);
    }

    public void sendMsgToTopicWithKey(String topic,String key,String msg){
        kafkaTemplate.send(topic,key,msg);
        log.debug("send with key over, topic:{}, key:{}, msg {}.",topic,key,msg);
    }

}
